package com.superpeer.baseproject.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.superpeer.baseproject.bean.BaseObject;
import com.superpeer.baseproject.R;
import com.superpeer.baseproject.api.Url;

import org.jetbrains.annotations.NotNull;


public class LearnNewsAdapter extends BaseQuickAdapter<BaseObject, LearnNewsAdapter.ViewHolder> {

    public LearnNewsAdapter() {
        super(R.layout.item_learn_news);
    }

    @Override
    protected void convert(@NotNull ViewHolder viewHolder, BaseObject bean) {
        if(null!=bean.getArticleImages()){
            Glide.with(getContext()).load(bean.getArticleImages().contains("http") ? bean.getArticleImages() : Url.IP + bean.getArticleImages()).centerCrop().into(viewHolder.ivImg);
        }
        if(null!=bean.getArticleTitel()){
            viewHolder.tvTitle.setText(bean.getArticleTitel());
        }
        if(null!=bean.getIntro()){
            viewHolder.tvContent.setText(bean.getIntro());
        }
        if(null!=bean.getCreateDate()){
            viewHolder.tvTime.setText(bean.getCreateDate());
        }
        if(null!=bean.getReadNumber()){
            viewHolder.tvBrowse.setText("浏览量 " + bean.getReadNumber());
        }
    }

    protected class ViewHolder extends BaseViewHolder{

        ImageView ivImg;
        TextView tvTitle;
        TextView tvContent;
        TextView tvTime;
        TextView tvBrowse;
        LinearLayout linearItem;

        public ViewHolder(@NotNull View view) {
            super(view);

            ivImg = view.findViewById(R.id.ivImg);
            tvTitle = view.findViewById(R.id.tvTitle);
            tvContent = view.findViewById(R.id.tvContent);
            tvTime = view.findViewById(R.id.tvTime);
            tvBrowse = view.findViewById(R.id.tvBrowse);
            linearItem = view.findViewById(R.id.linearItem);
        }
    }
}
